export const formatArticleContent = (
    content: string,
    imgUrl: string,
    toJson: boolean
) => {
    const newContent = content
        .replace(/<img/g, '<img style="max-width:100%;height:auto;"')
        .replace(/src="\/image\/(.*?)"/g, `src="${imgUrl}"`)
        .replace(/<\/?p>/g, "<p>")
        .replace(/<video(.*?)<\/video>/, "");
    if (toJson) {
        const data: { img?: Array<string>; p?: Array<string> } = {};
        newContent.split("<p>").forEach((text) => {
            if (text.includes("<img")) {
                const match = text.match(/src="(.*?)"/);
                if (match) {
                    data["img"] = data["img"]
                        ? [...data["img"], match[1]]
                        : [match[1]];
                }
            } else {
                if(text.trim() !== '' && text.trim() !== '\n') {
                    data["p"] = data["p"] ? [...data["p"], text] : [text];
                }
            }
        });
        return data;
    } else {
        return newContent;
    }
};
